package com.superdry.utils;

import java.io.File;

import com.ab.util.AbDialogUtil;
import com.ab.util.AbToastUtil;

import android.content.ComponentName;
import android.content.Context;
import android.content.Intent;
import android.content.pm.PackageManager;
import android.content.pm.PackageManager.NameNotFoundException;
import android.net.Uri;

public class ShareHelper {

	/**
	 * share to wechat 
	 * @param mContext
	 * @param file .file maybe null.
	 * */
	public static  void shareToWechat(Context mContext,File file)  {
        Intent intent = new Intent();
        ComponentName comp = new ComponentName("com.tencent.mm","com.tencent.mm.ui.tools.ShareImgUI");
        intent.setComponent(comp);
        intent.setAction("android.intent.action.SEND");
        intent.setType("image/*");                   
        intent.putExtra(Intent.EXTRA_TEXT,"我正在使用干洗超人，超方便！/n快点下载使用吧！");
        if(null != file)
        	intent.putExtra(Intent.EXTRA_STREAM, Uri.fromFile(file));
        if(checkPackage(mContext,"com.tencent.mm")){
        	mContext.startActivity(intent);
        }else{
        	AbToastUtil.showToast(mContext, "您未安装微信！");
        }
	}
	
	/**
	 * share to friends 
	 * @param mContext
	 * @param file .file maybe null.
	 * */
	public static void shareToTimeLine(Context mContext,File file) {
        Intent intent = new Intent();
        ComponentName comp = new ComponentName("com.tencent.mm","com.tencent.mm.ui.tools.ShareToTimeLineUI");
        intent.setComponent(comp);
        intent.setAction("android.intent.action.SEND");
        intent.setType("image/*");
        intent.putExtra(Intent.EXTRA_TEXT,"我正在使用干洗超人，超方便！/n快点下载使用吧！");
        if(null != file)
        	intent.putExtra(Intent.EXTRA_STREAM, Uri.fromFile(file));
        if(checkPackage(mContext,"com.tencent.mm")){
        	mContext.startActivity(intent);
        }else{
        	AbToastUtil.showToast(mContext, "您未安装微信！");
        }
	}

	/**
	 * share to qq 
	 * @param mContext
	 * @param file .file maybe null.
	 * */
	public static  void shareToQQFriend(Context mContext,File file) {
        Intent intent = new Intent();
        ComponentName componentName = new ComponentName("com.tencent.mobileqq", "com.tencent.mobileqq.activity.JumpActivity");
        intent.setComponent(componentName);
        intent.setAction(Intent.ACTION_SEND);
        intent.setType("text/*");
        intent.putExtra(Intent.EXTRA_TEXT, "我正在使用干洗超人，超方便！/n快点下载使用吧！");
        if(null != file)
        	intent.putExtra(Intent.EXTRA_STREAM, Uri.fromFile(file));
        if(checkPackage(mContext,"com.tencent.mobileqq")){
        	mContext.startActivity(intent);
        }else{
        	AbToastUtil.showToast(mContext, "您未安装QQ！");
        }
	}
	
	/**

     * 检测该包名所对应的应用是否存在

     * @param packageName

     * @return

     */

    public static boolean checkPackage(Context mContext,String packageName){ 

        if (packageName == null || "".equals(packageName)) 
            return false; 
        try{ 
            mContext.getPackageManager().getApplicationInfo(packageName, PackageManager.GET_UNINSTALLED_PACKAGES); 
            return true; 
        }
        catch (NameNotFoundException e){ 
            return false; 
        } 
    }

}
